Data Structures to use in Leetcode problems

Array - list List - list Hash Set - set Hash Map - dict, collections.Counter, collections.defaultdict Linked List - custom implementation Stack - list, ideally double-ended queue Queue - doubly-ended queue (collections.deque)

Usage Cases for Data Structures in Python

Stacks:

  • Parentheses Validation: Checking for balanced brackets (), ``, {}.
  • Expression Evaluation: Evaluating postfix (Reverse Polish Notation) or infix expressions.
  • Backtracking: Explicitly managing the state or path in iterative backtracking solutions.
  • Monotonic Stack: Finding the next/previous greater/smaller element, solving histogram problems.
  • Simulating Recursion: Converting recursive algorithms (like DFS) to iterative forms. Queues:
  • Breadth-First Search (BFS)
  • Level Order Traversal
  • Simulations: Modeling waiting lines, task scheduling, or any process following a FIFO order.

Advanced Data Structures